package com.example.config;

import liquibase.integration.spring.SpringLiquibase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * <pre>
 *      Liquibase 的配置文件
 *      可有可无
 * </pre>
 *
 * @author tao
 * @version v1.0.0
 * @since 2021/12/15 0:18
 */
//@Configuration
public class LiquibaseConfig {

    @Qualifier("dataSource")
    private DataSource dataSource;

    @Autowired
    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    @Bean
    public SpringLiquibase liquibase() {
        SpringLiquibase liquibase = new SpringLiquibase();
        liquibase.setDataSource(dataSource);
        liquibase.setChangeLog("classpath:db/changelog/db.changelog-master.xml");
        liquibase.setContexts("development,test,preproduction,production");
        liquibase.setShouldRun(true);
        return liquibase;
    }


}
